import { GridForm, KKP2D, KKP2DTable } from '@coldcloude/kakera';
import { _decorator, Component, Node, Sprite, SpriteAtlas } from 'cc';
import { NodeEx } from './lib/kakera-cocos/scripts/NodeEx';
import { createNode } from './Common';
import { SF_B_VALID } from './Constant';
const { ccclass, property } = _decorator;

@ccclass('BattleBlockController')
export class BattleBlockController extends Component {

    shape:KKP2D[];

    gridForm:GridForm;

    atlas:SpriteAtlas;

    spriteNodeMap = new KKP2DTable<NodeEx>();
    spriteMap = new KKP2DTable<Sprite>();

    init() {
        for(const pos of this.shape){
            const nn = createNode();
            this.node.addChild(nn);
            this.spriteNodeMap.set(pos,nn);
            const sprite = nn.addComponent(Sprite);
            sprite.spriteFrame = this.atlas.getSpriteFrame(SF_B_VALID);
            this.spriteMap.set(pos,sprite);
            const pp = this.gridForm.toPixel(pos);
            nn.setPosition(pp.x,pp.y);
        }
    }

    render(dt:number){

    }
}
